﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using EvoGame.Core.Files;
using EvoGame.Core.Interfaces;
using EvoGame.Core.Components;

namespace EvoGame.Ceeforee
{
	public partial class MainWin : Form
	{
		private PluginHost ph = new PluginHost();
		private FileHandler.Licence lic = new FileHandler.Licence();
		private FileHandler.Log logFile = new FileHandler.Log();

		public MainWin()
		{
			EvoGame.Core.Components.Application.Debug.Output = "Architecture found: " + System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", EnvironmentVariableTarget.Machine);
			ph.LoadFromDLL("EvoGame.Ceeforee.Core.dll");
			InitializeComponent();

			foreach (KeyValuePair<IPluggable, bool> plugin in ph.RegisteredPlugins)
			{
				if (!plugin.Value || !typeof(TabPage).IsAssignableFrom(plugin.Key.GetType())) continue;
				tabControl.TabPages.Add((TabPage)plugin.Key);
			}

			lic.Load();
			if (lic.IsValid())
			{
				TabPage debug = new TabPage("Debug");
				EvoGame.Core.Components.Application.Debug.Dock = DockStyle.Fill;
				debug.Controls.Add(EvoGame.Core.Components.Application.Debug);
				tabControl.TabPages.Add(debug);
			}
			lic.Close();
		}

		private void MainWin_FormClosed(object sender, FormClosedEventArgs e)
		{
			logFile.Save();
			logFile.Close();
		}

		private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
		{
			AboutBox ab = new AboutBox();
			ab.Show();
		}
	}
}
